<!DOCTYPE html>
<html lang="zh-cn">
<head>
	<meta http-equiv="Content-Type" content="multipart/form-data; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<meta name="renderer" content="webkit">
<title></title>
<link rel="stylesheet" href="css/pintuer.css">
<link rel="stylesheet" href="css/admin.css">
<script src="js/jquery.js"></script>
<script src="js/pintuer.js"></script>
</head>
<body>
<div class="panel admin-panel">
  <div class="panel-head" id="add"><strong><span class="icon-pencil-square-o"></span>增加内容</strong></div>
  <div class="body-content">
    <form method="post"  id="form-x" class="form-x" action="/workview/superviseadd1">

      <div class="form-group">
        <div class="label">
          <label>输入学号：</label>
        </div>
        <div class="field">
          <input type="text" class="input w50" value="" name="sno" id="sno" data-validate="required:请输入学号长度11位" />
          <span style="margin-left: 10px; color: red;">*</span>
          <div class="tips"> </div>
        </div>
      </div>

      <div class="form-group">
        <div class="label">
          <label>请输入密码：</label>
        </div>
        <div class="field">
          <input type="password" class="input w50" value="" name="password" id="password" data-validate="required:请输入密码" />
          <span style="margin-left: 10px; color: red;">*</span>
          <div class="tips"> </div>
        </div>
      </div>
		
		<div class="form-group">
		  <div class="label">
		    <label>再次输入密码：</label>
		  </div>
		  <div class="field">
		    <input type="password" class="input w50" value="" name="password1" id="password1" data-validate="required:请输入密码" />
		    <span style="margin-left: 10px; color: red;">*</span>
		    <div class="tips"> </div>
		  </div>
		</div>

      <div class="form-group">
        <div class="label">
          <label>添加姓名：</label>
        </div>
        <div class="field">
          <input type="text" class="input w50" value="" name="name" id="name" data-validate="required:请输入添加人的姓名" />
          <span style="margin-left: 10px; color: red;">*</span>
          <div class="tips"> </div>
        </div>
      </div>
	  
	  <div class="form-group">
	    <div class="label">
	      <label>添加学院：</label>
	    </div>
	    <div class="field">
	      <input type="text" class="input w50" value="" name="college_name" id="college_name" data-validate="required:请输入添加人的学院"/>
			<span style="margin-left: 10px; color: red;">*</span>
	      <div class="tips"> </div>
	    </div>
	  </div>

	  <div class="form-group">
		   <div class="label">
		     <label>添加年级：</label>
		   </div>
		   <div class="field">
		     <input type="text" class="input w50" value="" name="grade" id="grade" data-validate="required:请输入添加人的年级"/>
			   <span style="margin-left: 10px; color: red;">*</span>
		     <div class="tips"> </div>
		   </div>
	   </div>

		<div class="form-group">
			<div class="label">
				<label>添加班级：</label>
			</div>
			<div class="field">
				<input type="text" class="input w50" value="" name="class_name" id="class_name" data-validate="required:请输入添加人的班级"/>
				<span style="margin-left: 10px; color: red;">*</span>
				<div class="tips"> </div>
			</div>
		</div>
	 <div class="form-group">
	   <div class="label">
	     <label>备注：</label>
	   </div>
	   <div class="field">
	     <input type="text" class="input w50" value="" name="remark" id="remark"  />
	     <div class="tips"> </div>
	   </div>
	 </div>
   
      <div class="form-group">
        <div class="label">
          <label></label>
        </div>
        <div class="field">
          <button class="button bg-main icon-check-square-o" type="button" id="button bg-main icon-check-square-o" onclick="check1()"> 提交</button>
        </div>
      </div>
    </form>
  </div>
</div>

<script src="js/jquery.min.js"></script>
<script type="text/javascript">
	    function check1(){
	    var name = document.getElementById("name").value;
	    var password1 = document.getElementById("password1").value;
	    var password = document.getElementById("password").value;
		var sno = document.getElementById("sno").value;
		var grade = document.getElementById("grade").value;
		var college_name = document.getElementById("college_name").value;
		var class_name = document.getElementById("class_name").value;
	    var remark = document.getElementById("remark").value;
	    if(sno == null || sno == ""){
	        alert("学号不能为空");
	        return;
	    }
		if(sno.length !=11){
		    alert("学号为11位请输入11位");
		    return;
		}
	    if(name == null || name == ""){
	        alert("名字不能为空");
	        return;
	    }
	    if(password1 == null || password1 == ""){
	        alert("请再输入密码");
	        return;
	    }
		if(password == null || password == ""){
		    alert("请输入密码");
		    return;
		}
		if(password1 != password ){
		    alert("两次密码不一样");
		    return;
		}
		if(college_name == null || college_name == ""){
		    alert("请选择学院");
		    return;
		}
		if(grade == null || grade == ""){
		    alert("年级不能为空");
		    return;
		}
		if(class_name == null || class_name == ""){
                alert("班级不能为空");
                return;
		}
		if(remark == null || remark == ""){
                alert("选择输入备注");
                return;
		}
	    $.ajax({
            type:"POST",
            dataType:"json",
            url:"/workview1/studentAdd",
	        data: ({
                sno:sno,
                password:password,
                name:name,
                college_name:college_name,
                grade:grade,
                class_name:class_name,
                remark:remark
            }),
	        success:function(data){
	                console.log(data);
	                if(data.status==401){
	                    alert("熔断开启，系统异常");
	                    window.location.href="login.html";
	                    return;
	                }
	                if(data.status==200) {
	                    localStorage.setItem("supervise",data.data);
	                    window.location.href="studentlist.html";
	                    return;
	                }
	                if(data.status==500) {
	                    alert("添加失败");
	                    window.location.href="studentlist.html";
	                    return;
	                }
	                 if(data.status==null) {
	                    alert("添加异常");
	                    window.location.href="studentlist.html";
	                    return;
	                 }
	        },
	        error:function(XMLHttpRequest,textStatus) {
	            if (textStatus === 'timeout') {
	                alert('請求超時');
	                setTimeout(function () {
	                    alert('重新请求');
	                }, 2000);
	            }
	           // window.location.href="login.html";
                alert("系统异常ajax失败");
                window.location.href="studentlist.html";
	        }
	
	    });
	
	}
	
	
</script>
</body>
</html>